# read file

handler = open('sample.txt', encoding='UTF-8')
print(handler.read())  # 不加 encoding 如下 有中文会乱码或者报错
# handler = open('sample.txt')

# print(handler.read()) # 再次读为空
handler.close()

print('-' * 20)

handler2 = open('sample.txt', encoding='UTF-8')
print(handler2.readline())
print(handler2.readline())
handler2.close()

print('-' * 20)

handler3 = open('sample.txt', encoding='UTF-8')
print(handler3.readlines())
handler3.close()

print('-' * 20)

handler4 = open('sample.txt', encoding='UTF-8')
for x in handler4:
    print(x, end='')
